package com.htthorizon.model.controller;


import com.github.pagehelper.Page;
import com.htthorizon.common.core.context.SecurityContextHolder;
import com.htthorizon.common.core.domain.R;
import com.htthorizon.common.core.web.controller.BaseController;
import com.htthorizon.common.core.web.domain.AjaxResult;
import com.htthorizon.common.core.web.page.TableDataInfo;
import com.htthorizon.common.log.annotation.Log;
import com.htthorizon.common.log.enums.BusinessType;
import com.htthorizon.common.security.annotation.RequiresPermissions;
import com.htthorizon.model.domain.ModelMessage;
import com.htthorizon.model.mapper.ModelMessageNextUserMapper;
import com.htthorizon.model.request.ModelMessageAddReq;
import com.htthorizon.model.request.ModelMessageForward;
import com.htthorizon.model.request.ModelMessageReply;
import com.htthorizon.model.request.ModelMessageSearchReq;
import com.htthorizon.model.response.ModelMessageVo;
import com.htthorizon.model.service.IModelMessageFlowService;
import com.htthorizon.model.service.IModelMessageService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.*;

/**
 * @author Brilliant
 *
 * 反馈消息
 */
@RestController
@RequestMapping("/message")
@Slf4j
public class ModelMessageController extends BaseController {

    @Autowired
    private IModelMessageService modelMessageService;
    @PostMapping("/add")
    @RequiresPermissions("model:feedback:record")
    @Log(title = "模型管理/模型反馈消息", businessType = BusinessType.INSERT)
    public AjaxResult addMessage(@RequestBody @Valid ModelMessageAddReq search){
       boolean result = modelMessageService.addMessage(search);
       return AjaxResult.success(result);
    }
    @Autowired
    private IModelMessageFlowService modelMessageFlowService;
    @Autowired
    private ModelMessageNextUserMapper modelMessageNextUserMapper;

    @GetMapping("/page")
    @RequiresPermissions("model:feedback:record")
    @Log(title = "模型管理/模型反馈消息", businessType = BusinessType.QUERY)
    public TableDataInfo page(@Valid ModelMessageSearchReq search){
        Integer page =search.getPageNum();
        Integer pageSize = search.getPageSize();
        Page<ModelMessageVo> pages = new Page<>();
        pages.setPageNum(page);
        pages.setPageSize(pageSize);
        TableDataInfo tableDataInfo = new TableDataInfo();
        tableDataInfo.setCode(200);
        return modelMessageService.getPage(pages,search,tableDataInfo);
    }

    @GetMapping("/{id}")
    @RequiresPermissions("model:feedback:record")
    public AjaxResult getById(@PathVariable("id") Long id){
        ModelMessageVo modelMessage = modelMessageService.getById(id);
        return AjaxResult.success(modelMessage);
    }

    @PostMapping("/reply")
    @ApiOperation("回复")
    @RequiresPermissions("model:feedback:record")
    @Log(title = "模型管理/模型反馈消息回复", businessType = BusinessType.INSERT)
    public AjaxResult reply(@RequestBody @Valid ModelMessageReply modelMessageReply){
      boolean result=  modelMessageService.reply(modelMessageReply);
        return AjaxResult.success();
    }

    @PostMapping("/forward")
    @ApiOperation("转办")
    @RequiresPermissions("model:feedback:record")
    @Log(title = "模型管理/模型反馈消息转办", businessType = BusinessType.INSERT)
    public AjaxResult forward(@RequestBody @Valid ModelMessageForward modelMessageForward){
          boolean result=  modelMessageService.nextUser(modelMessageForward);
          return AjaxResult.success();
    }

    @GetMapping("/del")
    @ApiOperation("/撤销")
    @RequiresPermissions("model:feedback:record")
    @Log(title = "模型管理/模型反馈消息撤销", businessType = BusinessType.DELETE)
    public AjaxResult del(@RequestParam Long id){
        boolean result=  modelMessageService.del(id);
        return AjaxResult.success(result);
    }

}
